package HelperFinancial.DataBase;

import HelperFinancial.Class.Categorias;
import HelperFinancial.Class.Credito;
import HelperFinancial.Class.Debito;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class AlertHelper extends SQLiteOpenHelper {
	
	private static final String DATABASE_NAME="alerts.db";
	private static final int SCHEMA_VERSION=1;
	
	public AlertHelper(Context context) {
		super(context, DATABASE_NAME, null, SCHEMA_VERSION);
	}
	
	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL("CREATE TABLE alert (_id INTEGER PRIMARY KEY AUTOINCREMENT, balance_negative TEXT, debits TEXT);");
	}
	
	public void populate() {
		ContentValues cv = new ContentValues();
		cv.put("balance_negative", "sim");
		cv.put("debits", "sim");
		getWritableDatabase().insert("alert", "balance_negative", cv);
	}
	
	public Cursor getBalanceNegative() {
		return(getReadableDatabase()
		.rawQuery("SELECT balance_negative FROM alert",
		null));
	}
	
	public Cursor getViewDebits() {
		return(getReadableDatabase()
		.rawQuery("SELECT debits FROM alert",
		null));
	}
	
	public Cursor getId() {
		return(getReadableDatabase()
		.rawQuery("SELECT _id FROM alert",
		null));
	}
	
	public Cursor getAll(){
		return(getReadableDatabase()
				.rawQuery("SELECT * FROM alert",
				null));
	}
	
	
	public void removeAll() {
		getReadableDatabase().delete("alert", null, null);
	}
	
	public void changeViewDebits(int id, String value){
		ContentValues cv = new ContentValues();
		cv.put("debits", value);
		
		getReadableDatabase().update("alert", cv, "_id=" + id, null);
	}
	
	public void changeNegativeBalance(int id, String value){
		ContentValues cv = new ContentValues();
		cv.put("balance_negative", value);
		
		getReadableDatabase().update("alert", cv, "_id=" + id, null);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub
		
	}

	

	
	
}
